import { ReactElement } from 'react';
import type { IClassCompent as IClass } from '@inbiz/componentsWeb';
import { Field } from './common/Field';
import { Form } from './Form/designer';
export default getComponents

function getComponents(platform: 'web' | 'wap') {
  return (platform === 'web' ? import(`@inbiz/componentsWeb`) : import(`@inbiz/componentsWap`)).then(async ({ getComponents, getClassCompent, decorator}) => {
    const {component, classCompent } = await getComponents();
    return {
      component: {
        ...component,
        Field,
        Form,
        ...decorator
      },
      classCompent,
    } as unknown as {
      component: Record<string, ReactElement>;
      classCompent: IClassCompent[];
    };
  })
}

export type IClassCompent = Omit<IClass[number], 'data'> & {
  data: Record<
    string,
    {
      name: string;
      components: ReactElement[];
    }
  >;
};
